package com.liaozhai.community.controller;

import com.liaozhai.community.context.BaseContext;
import com.liaozhai.community.entity.User;
import com.liaozhai.community.service.FollowService;
import com.liaozhai.community.util.CommunityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
public class FollowController {

    @Autowired
    private FollowService followService;

    @PostMapping( "/follow")
    @ResponseBody
    public String follow(int entityType, int entityId) {
        User user = BaseContext.getUser();

        followService.follow(user.getId(), entityType, entityId);

        return CommunityUtil.getJSONString(0, "已关注!");
    }

    @PostMapping("/unfollow")
    @ResponseBody
    public String unfollow(int entityType, int entityId) {
        User user = BaseContext.getUser();

        followService.unfollow(user.getId(), entityType, entityId);

        return CommunityUtil.getJSONString(0, "已取消关注!");
    }

}
